package com.powernode.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.powernode.domain.HotSearch;
import com.powernode.service.HotSearchService;
import com.powernode.mapper.HotSearchMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 *
 */
@Service
public class HotSearchServiceImpl extends ServiceImpl<HotSearchMapper, HotSearch>
        implements HotSearchService {
    @Autowired
    private HotSearchMapper hotSearchMapper;

    @Override
    public Page<HotSearch> hotSearchPage(Page<HotSearch> page, HotSearch hotSearch) {
        return hotSearchMapper.selectPage(page, new LambdaQueryWrapper<HotSearch>()
                .like(StringUtils.hasText(hotSearch.getTitle()), HotSearch::getTitle, hotSearch.getTitle())
                .like(StringUtils.hasText(hotSearch.getContent()), HotSearch::getContent, hotSearch.getContent())
                .eq(!ObjectUtils.isEmpty(hotSearch.getStatus()), HotSearch::getStatus, hotSearch.getStatus()));
    }

    @Override
    public List<HotSearch> hotSearchByShopId(Integer number) {
        List<HotSearch> list = hotSearchMapper.selectList(new LambdaQueryWrapper<HotSearch>()
                .last(" limit " + number));
        return list;
    }
}




